#pragma once
#ifndef __APP_H__
#define __APP_H__

#include <msg/message.h>
#include <util/Endpoint.hpp>

class App
{
public:
    App(int fd);

    uint32_t get_app_id();

    Endpoint get_sender();

    Endpoint get_receiver();

    int get_fd();

protected:
    void send_message_to(message msg, Endpoint receiver);

    bool send_to_fd(std::span<char> data);

private:
    // sender 在 router.register_app 中设置
    void set_sender(Endpoint sender);

    // receiver 由 RouterController 设置
    void set_receiver(Endpoint receiver);

    virtual void message_hander(message msg) = 0;

    virtual void fd_hander() = 0;

    friend class RouterClient;
    friend class RouterControlServer;

private:
    Endpoint sender;
    Endpoint receiver;
    int const fd;
};



#endif // __APP_H__